package com.imooc.web.async;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author Zqm
 * @Title: MockQueue
 * @ProjectName imooc-security
 * @date 2018/12/18
 *
 * 手动模拟消息队列对象
 */
@Component
public class MockQueue {
    private Logger logger= LoggerFactory.getLogger(getClass());

    /**
     * 订单消息
     */
    private String placeOrder;

    /**
     * 订单完成消息
     */
    private String completeOrder;


    public String getPlaceOrder() {
        return placeOrder;
    }

    /**
     * 虚拟队列
     * @param placeOrder
     * @throws InterruptedException
     */
    public void setPlaceOrder(String placeOrder)  {
        new Thread(() -> {
            logger.info("接到下单请求, " + placeOrder);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.completeOrder = placeOrder;
            logger.info("下单请求处理完毕," + placeOrder);
        }).start();
    }

    public String getCompleteOrder() {
        return completeOrder;
    }

    public void setCompleteOrder(String completeOrder) {
        this.completeOrder = completeOrder;
    }
}
